home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_333 / multiplot / source / plt2dr_src / plot2draw.c < prev   
C/C++ Source or Header  |  1992-05-06  |  6KB  |  252 lines

  1. #include <exec/types.h>
  2. #include <stdio.h>
  3. #include <exec/memory.h>
  4. #include "libraries/dos.h"
  5. #include "exec/exec.h"
  6. #include "intuition/intuitionbase.h"
  7. #include "devices/keymap.h"
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <stdlib.h>
  11.  
  12. #include "drawicon.h"
  13. struct IntuitionBase *IntuitionBase;
  14. struct IconBase *IconBase;
  15.  
  16. int FLAG;
  17. char line[100];
  18. double x;
  19. double minx;
  20. double Minx;
  21. double maxx;
  22. double Maxx;
  23. double y;
  24. double miny;
  25. double Miny;
  26. double maxy;
  27. double Maxy;
  28.  
  29. struct coord {
  30.   int          number;
  31.   double        across;
  32.   double       up;
  33.   struct coord *next;
  34. };
  35.  
  36. typedef struct coord ELEMENT;
  37. typedef ELEMENT *LINK;
  38. LINK head = NULL;
  39. LINK place = NULL;
  40.  
  41. struct part {
  42.   int partnumber;
  43.   int from;
  44.   int to;
  45.   double minx;
  46.   double maxx;
  47.   double miny;
  48.   double maxy;
  49.   struct part *next;
  50.   struct part *last;
  51. };
  52.  
  53. typedef struct part PART;
  54. typedef PART *PPART;
  55. PPART firstpart =NULL;
  56. PPART thispart = NULL;
  57. PPART lastpart = NULL;
  58.  
  59.  
  60. int i=0;
  61. int k=1;
  62. int j,l;
  63.  
  64. char plot_name[100];
  65. char draw_name[100];
  66.  
  67.  
  68.  
  69. void main(argc,argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.  
  74. FILE *fp1, *fp2;
  75. LINK getplace();
  76. PPART getpart();
  77.  
  78.   /*** PARSE ARGS ***/
  79.  
  80.   if ((argv[1][0] == '?')||(argc!=3))
  81.      {
  82.         printf("usage: Plot2Draw infile outfile\n");
  83.         exit(0);
  84.      }
  85.    else
  86.      {
  87.        strcpy(plot_name,argv[1]);
  88.        strcpy(draw_name,argv[2]);
  89.      }
  90.  
  91.    /*** OPEN LIBRARIES ***/
  92.  
  93.    if (!(IntuitionBase = OpenLibrary("intuition.library",0))) {
  94.       printf("Can't open intuition library...\n");
  95.       exit(0);
  96.    }
  97.    if (!(IconBase = OpenLibrary("icon.library", 0))) {
  98.       printf("Can't open icon library...\n");
  99.       CloseLibrary(IntuitionBase);
  100.       exit(0);
  101.    }
  102.  
  103.    /*** GET DATA FROM FILE ***/
  104.  
  105.    fp1 = NULL;
  106.    if (*plot_name) fp1 = fopen(plot_name,"r");
  107.    if (fp1==NULL)
  108.       {
  109.          printf("Input file does not exist.\n");
  110.          exit(0);
  111.       }
  112.    fp2 = NULL;
  113.    if (*draw_name) fp2 = fopen(draw_name,"w");
  114.    if (fp2==NULL)
  115.       {
  116.          printf("Unable to open Output File.\n");
  117.          exit(0);
  118.       }
  119.  
  120.  
  121.    do { fgets(line,100,fp1); }
  122.        while (sscanf(line,"%lf %lf",&x,&y)==NULL);
  123.    Minx=Maxx=minx=maxx=x;
  124.    Miny=Maxy=miny=maxy=y;
  125.    head =(LINK)malloc(sizeof(ELEMENT));
  126.    head->number=i++;
  127.    head->across=x;
  128.    head->up=y;
  129.    head->next=(LINK)malloc(sizeof(ELEMENT));
  130.    place=head->next;
  131.     do {
  132.           fgets(line,100,fp1);
  133.           FLAG=sscanf(line,"%lf %lf",&x,&y);
  134.           if ((FLAG!=NULL)&&(FLAG!=EOF))
  135.             {
  136.               if (x<minx) minx=x;
  137.               if (x<Minx) Minx=x;
  138.               if (x>maxx) maxx=x;
  139.               if (x>Maxx) Maxx=x;
  140.               if (y<miny) miny=y;
  141.               if (y<Miny) Miny=y;
  142.               if (y>maxy) maxy=y;
  143.               if (y>Maxy) Maxy=y;
  144.               place->number=i++;
  145.               place->across=x;
  146.               place->up=y;
  147.               place->next=(LINK)malloc(sizeof(ELEMENT));
  148.               place=place->next;
  149.             }
  150.        } while ((FLAG!=NULL)&&(FLAG!=EOF));
  151.    firstpart =(PPART)malloc(sizeof(PART));
  152.    firstpart->last=NULL;
  153.    firstpart->partnumber=k++;
  154.    firstpart->from=0;
  155.    firstpart->to=i;
  156.    firstpart->minx=minx;
  157.    firstpart->miny=miny;
  158.    firstpart->maxx=maxx;
  159.    firstpart->maxy=maxy;
  160.    firstpart->next =(PPART)malloc(sizeof(PART));
  161.    firstpart->next->last=firstpart;
  162.    thispart=firstpart->next;
  163.  
  164.    while (FLAG!=EOF) {
  165.  
  166.      do { fgets(line,100,fp1); }
  167.          while (sscanf(line,"%lf %lf",&x,&y)==NULL);
  168.      minx=maxx=x;
  169.      miny=maxy=y;
  170.      place->number=i++;
  171.      place->across=x;
  172.      place->up=y;
  173.      place->next=(LINK)malloc(sizeof(ELEMENT));
  174.      place=place->next;
  175.  
  176.       do {
  177.           fgets(line,100,fp1);
  178.           FLAG=sscanf(line,"%lf %lf",&x,&y);
  179.           if ((FLAG!=EOF)&&(FLAG!=NULL))
  180.             {
  181.             if (x<minx) minx=x;
  182.             if (minx<Minx) Minx=minx;
  183.             if (x>maxx) maxx=x;
  184.             if (maxx>Maxx) Maxx=maxx;
  185.             if (y<miny) miny=y;
  186.             if (miny<Miny) Miny=miny;
  187.             if (y>maxy) maxy=y;
  188.             if (maxy>Maxy) Maxy=maxy;
  189.             place->number=i++;
  190.             place->across=x;
  191.             place->up=y;
  192.             place->next=(LINK)malloc(sizeof(ELEMENT));
  193.             place=place->next;
  194.           }
  195.  
  196.        } while ((FLAG!=NULL)&&(FLAG!=EOF));
  197.      thispart->partnumber=k++;
  198.      thispart->from=1+thispart->last->to;
  199.      thispart->to=i;
  200.      thispart->minx=minx;
  201.      thispart->miny=miny;
  202.      thispart->maxx=maxx;
  203.      thispart->maxy=maxy;
  204.      thispart->next =(PPART)malloc(sizeof(PART));
  205.      thispart->next->last=thispart;
  206.      thispart=thispart->next;
  207.   }
  208.   fprintf(fp2,"81086 %f %f %f %f 0 1.00000 \"%s\"\n",Minx,Miny,Maxx,Maxy,draw_name);
  209.   fprintf(fp2,"-1\n");
  210.   for (l=1; l<k; l++)
  211.      {
  212.         thispart=getpart(firstpart,l);
  213.         fprintf(fp2,"1 52 %f %f %f %f 4 0 0 0 0 \n",thispart->minx,thispart->miny,thispart->maxx,thispart->maxy);
  214.         for (j=thispart->from; j<thispart->to; j++)
  215.           {
  216.              place=getplace(head,j);
  217.              fprintf(fp2,"       1 %f %f\n",place->across,place->up);
  218.           }
  219.         fprintf(fp2,"       0\n");
  220.      }
  221.   fprintf(fp2,"-1\n");
  222.  
  223.   fclose(fp1);
  224.   fclose(fp2);
  225.   PutDiskObject(draw_name,&IconDiskObject);
  226.  
  227.    CloseLibrary(IntuitionBase);
  228.    CloseLibrary(IconBase);
  229.  
  230. }
  231.  
  232.  
  233. LINK getplace(place,x)
  234. LINK place;
  235. int x;
  236. {
  237.     while (place->number<x)
  238.     place=place->next;
  239.     return(place);
  240. }
  241.  
  242.  
  243. PPART getpart(part,x)
  244. PPART part;
  245. int x;
  246. {
  247.     while (part->partnumber<x)
  248.     part=part->next;
  249.     return(part);
  250. }
  251.  
  252.